//
//  ModifyPswViewController.m
//  IMChat
//
//  Created by Admin on 2021/6/28.
//  Copyright © 2021年 TeamOne. All rights reserved.
//

#import "ModifyPswViewController.h"


@interface ModifyPswViewController ()

//返回按钮
- (IBAction)cancel:(id)sender;

//旧密码
@property (weak, nonatomic) IBOutlet UITextField *oldPsw;

//新密码
@property (weak, nonatomic) IBOutlet UITextField *pswNew;

//确认密码
@property (weak, nonatomic) IBOutlet UITextField *surePsw;

//确认修改按钮
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;


//确认修改按钮点击
- (IBAction)sureBtnClick:(UIButton *)sender;


@end

@implementation ModifyPswViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //监听文本框内容
    [self.oldPsw addTarget:self action:@selector(textFieldValueChanged:) forControlEvents:(UIControlEventEditingChanged)];
    [self.pswNew addTarget:self action:@selector(textFieldValueChanged:) forControlEvents:(UIControlEventEditingChanged)];
    [self.surePsw addTarget:self action:@selector(textFieldValueChanged:) forControlEvents:(UIControlEventEditingChanged)];
    
}

//取消按钮点击事件
- (IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}

//点击空白处回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

//搜索框有内容时登录按钮才能用
- (void)textFieldValueChanged:(UITextField *)textField {
    NSLog(@"你输入了%@", textField.text);
    self.sureBtn.enabled = self.oldPsw.text.length && self.pswNew.text.length && self.surePsw.text.length ;
}

- (IBAction)sureBtnClick:(UIButton *)sender {
    NSLog(@"你点击了确认修改！");
    if (self.pswNew.text == self.surePsw.text) {
        NSLog(@"修改密码");
    }
    //新密码和确认密码不相等，空格弹出警示
    else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"两次密码输入不一致！" message:nil preferredStyle:UIAlertControllerStyleAlert];//先创建一个弹窗控制器 然后里面有title和message来提示需要的东西
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];//添加一个弹窗的action 活动可以是取消 可以是确认
        [alert addAction:sureAction];
        [self presentViewController:alert animated:NO completion:nil];
        
        self.pswNew.text = @"";
        self.surePsw.text = @"";
        [self.pswNew becomeFirstResponder];
        return;
    }
    
}



@end
